<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="btn">点击弹出对话框</button>
    <div id="nav">你中奖了！</div>
    <script>
        // 获取事件源
        var btn = document.getElementById('btn');
        // 触发事件包括点击，鼠标经过，键盘，滚轮等等
        btn.onclick = function() {
            alert('出来了');
        }
        var nav = document.getElementById('nav');
        nav.onclick = function() {
            alert('中了');
        }
    </script>
</body>
</html>